var gulp = require('gulp');
var uglify = require('gulp-uglify');
var clean = require('gulp-clean');
var runSequence = require('run-sequence');
var connect = require('gulp-connect');
var config = require('./config.json');

gulp.task("clean", function () {
    return gulp.src(config.build)
        .pipe(clean());
})

gulp.task('vendor', function () {
    return gulp.src(config.js.vendor, {base: config.src})
        .pipe(gulp.dest(config.build));
});

gulp.task('compress', function () {
    return gulp.src(config.js.src, {base: config.src})
        .pipe(uglify({mangle: {except: ['require', 'exports', 'module', '$']}}))
        .pipe(gulp.dest(config.build));
});

gulp.task('html', function () {
    return gulp.src(config.html.src, {base: config.src})
        .pipe(gulp.dest(config.build));
});

gulp.task('webserver', function () {
    connect.server({root: config.build});
});

gulp.task('default-compress', function () {
    return runSequence('clean', 'vendor', 'compress', 'html');
});

gulp.task('default-run', function () {
    return runSequence('default-compress', 'webserver');
});